package br.com.moxeon.model.financialitems;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.com.moxeon.model.enums.CheckSituation;
import br.com.moxeon.model.enums.PersonType;
import br.com.vexillum.model.annotations.Validate;


@SuppressWarnings("serial")
@Table(name = "check_")// (_) pois a palavra check é restrita do banco de dados.
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Check extends FinancialItem {

	@Column(nullable = false)
	@Validate(notNull=true)
	private String number;

	@Enumerated
	@Column(nullable = false)
	///Não existe validação de não nula pois a situação do cheque é setada
	///via programação, ou seja, se der erro é erro de progamação, não de usuário
	private CheckSituation situation;

	@Column(name = "issue_date")
	//issueDate: data de emissão.
	private Date issueDate;

	private String issuing;

	@Validate(notNull=true)
	@Column(nullable=false)
	private String holder;

	@Enumerated
	@Column(name = "holder_type", nullable=false)
	@Validate(notNull=true)
	private PersonType holderType;

	private String cgc;

	private Date maturity;

	@OneToMany(targetEntity = CheckActions.class, mappedBy = "check", fetch = FetchType.LAZY)
	@Cascade(value = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.SAVE_UPDATE})
	private List<CheckActions> actions;

	private String observation;
	
	public String getNumber() {
		return number;
	}

	public CheckSituation getSituation() {
		return situation;
	}

	public Date getIssueDate() {
		return issueDate;
	}


	public String getIssuing() {
		return issuing;
	}

	public String getHolder() {
		return holder;
	}

	public PersonType getHolderType() {
		return holderType;
	}

	public String getCgc() {
		return cgc;
	}

	public Date getMaturity() {
		return maturity;
	}

	public List<CheckActions> getActions() {
		return actions;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public void setSituation(CheckSituation situation) {
		this.situation = situation;
	}

	public void setIssueDate(Date issueDate) {
		this.issueDate = issueDate;
	}

	public void setIssuing(String issuing) {
		this.issuing = issuing;
	}

	public void setHolder(String holder) {
		this.holder = holder;
	}

	public void setHolderType(PersonType holderType) {
		this.holderType = holderType;
	}

	public void setCgc(String cgc) {
		this.cgc = cgc;
	}

	public void setMaturity(Date maturity) {
		this.maturity = maturity;
	}

	public void setActions(List<CheckActions> actions) {
		this.actions = actions;
	}

	public String getObservation() {
		return observation;
	}

	public void setObservation(String observation) {
		this.observation = observation;
	}
	
	public String getNumberWithHolder()
	{
		return getNumber() + " - " + getHolder();
	}

}